/**
 * @file tiny_initer.h
 * @author 张恒宣 
 * @LastEditTime 2025/4/07
 * @note 使用需要在Linker下的Misc Controls下配置--keep *.o(.fn.*) IS_OPEN_INITER给PROFILE_OPEN
 
 * MIT License
 *
 * Copyright (c) 2025 张恒宣 luckkeymail@163.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

#ifndef __TINY_INITER_H__
#define __TINY_INITER_H__

#include "tiny_def.h"

/**********************
 *      类型定义
 **********************/

typedef void (*initer_f_t)(void);

/**********************
 *       宏定义
 **********************/
 
#define USED           __attribute__((used))
#define SECTION(name)  __attribute__((section(name)))

#if IS_OPEN_INITER == PROFILE_OPEN
#define EXPORT_INIT(obj, level) static USED initer_f_t obj##_init SECTION(".fn."level) = obj
#else
#define EXPORT_INIT(obj, level)
#endif

/// @brief 导出设备初始化
#define EXPORT_DRIVER(obj) EXPORT_INIT(obj, "1")

/// @brief 导出模块初始化
#define EXPORT_MOUDLE(obj) EXPORT_INIT(obj, "2")

/// @brief 导出应用初始化
#define EXPORT_APPLICATION(obj) EXPORT_INIT(obj, "3")

#endif //!__TINY_INITER_H__


